package io.github.maojian.doublepointer;

import org.junit.Test;

/**
 * 1750. 删除字符串两端相同字符后的最短长度
 */
public class Q1750 {

    public int minimumLength(String s) {
        int start = 0;
        int end = s.length() - 1;
        while (start < end && s.charAt(start) == s.charAt(end)) {
            char c = s.charAt(start);
            while (start <= end && s.charAt(start) == c) {
                start++;
            }
            while (start <= end && s.charAt(end) == c) {
                end--;
            }
        }
        return end - start + 1;
    }

    @Test
    public void test() {
        String s = "cabaabac";
        System.out.println(minimumLength(s));

        s = "aabccabba";
        System.out.println(minimumLength(s));
    }
}
